<?php
/**
 * 《生产计划》实现类
 *
 * @author 孙晓晔
 * @version $Id: Plan.class.php 1056 2010-04-08 05:15:48Z sunxy $
 */
require_once(dirname(__FILE__) . '/Plan.class.php');

class PlanMy extends Plan {

	function __construct() {
		$request['update'] = '$Date: 2009/02/16 07:36:07 $';
		$request['revision'] = '$Revision: 1.1 $';

		parent::__construct($request);
	}

	function _my() {		
		$emp = $_SESSION['id'];
		
		return sprintf(" visible = 1 AND (emp = '%s' OR worker = '%s' OR oper = '%s')", $emp, $emp, $emp);
	}
	
	function find($controller, $request) {
		$this->pretreat($controller);
	
		$controller->assign('t1', strtotime('-1 month'));
	
		$controller->assign('orderby_s', "t2");
		$controller->assign('desc_s', "1");
	
		$controller->assign('status_id', array(2, 3));
	
		$ab = array(
			'-' => '请选择',
			'1' => '格式1',
			'2' => '格式2',
			'3' => '格式3',
		);
		$controller->assign_by_ref('ab_option', $ab);
	
		$emp = array(
			// '-' => '请选择',
			'worker' => '负责人',
			'emp' => '计划人',
			
			'oper' => '录入员',
		);
	
		$controller->assign_by_ref('emp_option', $emp);
	
		$controller->display($request, 'mold/plan/my/find');
		return true;
	}
	
	/**
	 *
	 *
	 * @param Controler $controller
	 * @param array $request
	 */
	function findPost($controller, $request) {
		$this->pretreat($controller);
	
		$this->findPara($controller, $request);
	
		$db = newdb($this->dsn_r);
		$fmt = "SELECT * FROM %s a %s %s";
		$where = $this->_where($request);
		$orderby = $this->_orderby();
		$sql = sprintf($fmt, $this->tbl, $where, $orderby);
		debug($sql);
	
		$pager_option = array (
				'db' => $db,
				'sql' => $sql,
				'PageSize' => $this->pagesize,
				'CurrentPageID' => $request['p'],
				'numItems' => $request['n']
		);
	
		$pager = @new Pager($pager_option);
		$data = $pager->getPageData();
	
		if ($pager->number > 0) {
	
			$count = 0;
			$from = $pager->from;
			while ($count < $pager->number) {
				$row = $data[$count];
				$row = $this->_view(null, $row);
	
				$row = $this->_orderby_x($controller, $row, $this->orderby_s);
	
				$data[$count] = $row;
				$count++;
			}
			$controller->assign_by_ref('result', $data);
			$controller->assign_by_ref('pager', $pager);
		} else {
			$controller->clear_assign('result');
		}
	
		$controller->display($request, 'mold/plan/my/list');
		return true;
	}
	
}
?>